﻿using System;

namespace learnCsharp1
{
    public class Solution {
        public int PivotIndex(int[] nums) {
            if (nums.Length == 0) return -1;
            int left = 0,right = 0;
            for (int i = 0; i < nums.Length; i++)
                right += nums[i];
            {
            }
            right = right - nums[0];
            for (int i = 0,length = nums.Length; i < length; ++i) {
                if (left == right) return i;
                left += nums[i];
                right -= nums[i+1];
            }
            return -1;
        }
        static void Main(String[] args)
        {
            int[] nums = new[] {1, 7, 3, 6, 5, 6};
            string result = String.Join(",", nums);
            Console.WriteLine("测试样例："+result);
            Console.WriteLine("返回下标："+new Solution().PivotIndex(nums).ToString());
        }
    }
}